const { request } = require('../../utils/request');
const pageBehavior = require('../../utils/pageBehavior');
const { navigateTo } = require('../../utils/navigation');

Page({
  behaviors: [pageBehavior],

  async onSubmit(event) {
    const data = event.detail?.value || {};
    await this.executeAsync(
      async () => {
        await request({
          url: '/api/miniapp/profile/register',
          method: 'POST',
          data
        });
        this.showSuccess('保存成功');
        navigateTo('/pages/profile/profile', {}, 'redirectTo');
      },
      {
        showLoading: true,
        showError: true
      }
    );
  }
});
